var core = require('../../utils/core.js')

Page({
  data: {
    focus: false,
    inputValue: '',
    id:'',
    username:'',
    company_name:'',
    mobile:'',
    mobileFlag:false
  },
  onShow:function(){
   
  },
  onLoad:function(options){
    var userinfo=wx.getStorageSync('userinfo')
    if(userinfo){
      userinfo=JSON.parse(userinfo)
      this.setData({username:userinfo.nickName})
    }
    if(options.id){
      this.setData({id:options.id})
    }
  },
  
  getval(e) {
    var name=e.target.id
    this.setData({
      [name]: e.detail.value
    })
  },
  submit:function(){

    var self=this
    var data={
      id:self.data.id,
      username:self.data.username,
      company_name:self.data.company_name,
      mobile:self.data.mobile,
      op:'LiuYan'    
    }
    core.post("LocalProjects",data,function(res){
      if(res.code==1){
        wx.showToast({
          'title':res.msg,
          'icon':'success',
          success:function(){           
            setTimeout(function(){
              wx.navigateBack({
                delta: 1
              })
            },1000)           
          }
        })
       
      }else{
        wx.showToast({
          'title':res.msg,
          'icon':'none'
        })
      }
    })
  },
  getMobile:function(e){
    var iv=e.detail.iv
    var self=this
    var encryptedData=e.detail.encryptedData
    wx.login({
      success: res => {
       
        core.post('Getopenid',{code:res.code},function(res){
          var  data=JSON.parse(res.content);
          
          core.post('GetUserphone',{sessionKey:data.session_key,iv:iv,encryptedData:encryptedData},function(res){
            console.log(res)
           if(res.data.phoneNumber){
              self.setData({mobile:res.data.phoneNumber,mobileFlag:true})        
           }
          })

        })
      }
    })
  }
  
})
